import { ElMessage } from "element-plus";
/**
 * 复制文本
 * @param {*} text: string 
 */
export const copyText = (text) => {
      let tempInput = document.createElement("textarea");
      tempInput.value = text;
      document.body.appendChild(tempInput);
      tempInput.select();
      try {
        let successful = document.execCommand('copy');
        if(successful){
          ElMessage?.success("复制成功");
        }else{
          ElMessage?.error("复制失败，请手动复制");
        }
      } catch (err) {
        ElMessage?.error("复制异常");
      }
      document.body.removeChild(tempInput);
};

/**
 * 将富文本内容转换为纯文本内容
 * @param {*} htmlContent 
 * @returns 
 */
export function convertRichTextToPlainText(htmlContent) {
  let tempDiv = document.createElement("div");
  tempDiv.innerHTML = htmlContent;
  let plainText = tempDiv.textContent || tempDiv.innerText;
  tempDiv = null;
  return plainText;
}